package antsclub.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import antsclub.common.Encrypt;
import antsclub.model.Activity;
import antsclub.model.User;
import antsclub.model.Video;
import antsclub.model.VideoType;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.core.Controller;
import com.jfinal.kit.JsonKit;

import javax.servlet.http.HttpSession;

public class VideoController extends Controller{
	public void index(){
		String typeId="8ee6df61-0c06-42b4-b2f7-4fbaf43d9f78";
		String pageNumber=getPara(0);
		List<Video> list=Video.dao.find("select * from video " +
				" where typeId=?"+
				" order by seq limit "+(Integer.parseInt(pageNumber)-1)*12+",12",typeId);
		JSONObject json = new JSONObject();
		json.put("list", list);
		renderJson(JsonKit.toJson(json));
	}
	public void save(){
		try{
			Video v=getModel(Video.class);
			v.set("id", UUID.randomUUID().toString());
			v.set("typeId", "8ee6df61-0c06-42b4-b2f7-4fbaf43d9f78");
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
			String currentTime=df.format(new Date());// new Date()为获取当前系统时间
			v.set("createTime", currentTime);
			v.set("updateTime", currentTime);
			boolean b=v.save();
			if(b){
				setAttr("msg", "视频分享成功");
				render("/video/video_list.jsp");
			}else{
				setAttr("msg", "视频分享失败");
				render("/video/video_add.jsp");
			}
		}catch(Exception e){
			setAttr("msg", e);
			render("/video/video_add.jsp");
		}
		
		
	}	
	public void saveType(){
		try{
			VideoType v=getModel(VideoType.class);
			v.set("id", UUID.randomUUID().toString());
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
			String currentTime=df.format(new Date());// new Date()为获取当前系统时间
			v.set("createTime", currentTime);
			v.set("updateTime", currentTime);
			boolean b=v.save();
			if(b){
				setAttr("msg", "视频分类添加成功");
				render("/video/video_list.jsp");
			}else{
				setAttr("msg", "视频分类添加失败");
				render("/video/videoType_add.jsp");
			}
		}catch(Exception e){
			setAttr("msg", e);
			render("/video/videoType_add.jsp");
		}
		
		
	}
}
